import './App.css';
import React,{Component} from "react";
import * as echarts from 'echarts';
import 'whatwg-fetch'

class App extends Component {
    constructor(props) {
        super(props)
        this.state = {
            chartData:{}
        }

    }
    componentDidMount() {
        // var myChart = echarts.init(document.getElementById("myCharts"))
        var time = [];//x轴
        var nums = [];//y轴
        //http://127.0.0.1:8088/allHttp
        fetch("/allHttp", {
            method: 'POST',
            headers: {
                'X-AURORA-TOKEN': 'a525f3c52d134800b965139c1d3306ae'
            },
            mode: 'cors',
            cache: 'default',
            dataType:'json',
            success : function (res){
                if (res){
                    var obj = eval(res);
                    for (var i=0;i<obj.length;i++){
                        time.push(res[i].time);//挨个取出时间并放入数组
                    }
                    for (var i=0;i<obj.length;i++){
                        nums.push(res.num)//挨个取出访问量并放入数组
                    }


                }
            },
        }).then(res=>{
            return res.json();
        }).then(res =>{
             // var cc= res.content;
            // alert("cc:"+cc[1].api_visits_count_num)


            // const objToStr = JSON.stringify(aa)
            let myChart = echarts.init(document.getElementById("myCharts"))
            let option = {
                title: {
                    text: '平台每日http总访问量统计'
                },
                tooltip: {},
                xAxis:{
                    type:'category',
                    data:[]
                },
                yAxis:{
                    type: 'value'
                },
                series:[{
                    name:'访问量',
                    data:[20],
                    type: 'bar',
                }]
            }
            myChart.setOption(option)
        })

    }

    render() {
        return (
            <div id="myCharts" style={{width: "100%", height: 500}}>
            </div>
        )
    }
}
export default App;
